package com.comdev.ctrls;

import com.baidu.bae.api.util.BaeEnv;
import com.comdev.common.Reps;
import com.comdev.exceptions.CommonOut;
import com.dbutils.DBManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

/**
 * User: zhu
 * Date: 13-10-26
 * Time: 上午5:51
 */
@Controller
@RequestMapping("dbinfo")
public class dbinfo
{

    @ResponseBody
    @RequestMapping("get")
    public Map get()
    {
        Map out = new HashMap<String, String>();
        try
        {
            String host = BaeEnv.getBaeHeader(BaeEnv.BAE_ENV_ADDR_SQL_IP);
            String port = BaeEnv.getBaeHeader(BaeEnv.BAE_ENV_ADDR_SQL_PORT);
            String username = BaeEnv.getBaeHeader(BaeEnv.BAE_ENV_AK);
            String password = BaeEnv.getBaeHeader(BaeEnv.BAE_ENV_SK);

            Reps.add(out,"host",host);
            Reps.add(out,"port",port);
            Reps.add(out,"username",username);
            Reps.add(out,"password",password);


//            Connection con= DBManager.getConnection();
//            Reps.add(out,"con",con);

        } catch (CommonOut e)
        {
            Reps.add(out, e);
            return out;
        } catch (Exception e)
        {
            Reps.add(out, e);
            return out;
        }
        Reps.success(out);
        return out;
    }


    @RequestMapping("init")
     public ModelAndView  init()
     {
         ModelAndView mod=new ModelAndView();
         mod.setViewName("dbinfo");
         return  mod;

     }

}
